<%= render partial: 'shipit/stacks/header', locals: { stack: @stack } %>

<div class="wrapper">
  <section>
    <header class="section-header">
      <h2>Settings (Stack #<%= @stack.id %>)</h2>
    </header>

    <%= render partial: 'shipit/stacks/settings_form', locals: { stack: @stack } %>

    <div class="setting-section">
      <h5>Resynchronize this stack</h5>
      <table>
        <tr>
          <td><%= button_to "Clear Git Cache", stack_clear_git_cache_path(@stack), class: "btn", method: "post" %></td>
          <td>Delete the local git mirror in case it's in a bad state.</td>
        </tr>
      </table>
    </div>

    <div class="setting-section setting-ccmenu">
      <h5>Miscellaneous</h5>
      <div class="field-wrapper">
        <label>CCMenu URL (choose “Use URL as entered above” during CCMenu setup)</label>
        <input id="ccmenu-url" class="hidden" type="text" disabled />
      </div>
      <%= button_to "Fetch URL", "", class: 'btn', data: {remote: ccmenu_url_url(stack_id: @stack.to_param)} %>
    </div>

    <div class="setting-section">
      <% if @stack.archived? %>
        <h5>Restore Stack</h5>
        <p>This action will de-archive the Stack, restoring it in the stack list and unlocking it.</p>
        <%= form_with scope: :stack, url: stack_path(@stack), method: :patch do |f| %>
          <%= f.hidden_field :archived, value: false %>
          <%= f.submit class: "btn", value: "Restore" %>
        <% end %>
      <% else %>
        <h5>Archive Stack</h5>
        <p>This action will archive the Stack, hiding it from the stack list and locking it. It can still be found if you know the URL and de-archived.</p>
        <%= form_with scope: :stack, url: stack_path(@stack), method: :patch do |f| %>
          <%= f.hidden_field :archived, value: true %>
          <%= f.submit class: "btn", value: "Archive" %>
        <% end %>
      <% end %>
    </div>

    <div class="setting-section">
      <h5>Delete this stack</h5>
      <p>This action will delete the stack from Ship it permanently. Be careful.</p>
      <%= button_to "Delete…", stack_path(@stack), class: 'btn btn--delete', data: {confirm: 'Are you sure?'}, method: :delete %>
    </div>

  </section>
</div>
